﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using MySql.Data.MySqlClient;

namespace PropertyManagement.xinwen
{
    public partial class deleteXinWen : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                BindData();
            }
        }

        public void BindData()
        {
            string strsql = "select * from sxinwen";
            mydata myda = new mydata();
            DataSet ds = myda.getDataSet(strsql, "sxinwen");
            GridView1.DataKeyNames = new string[] { "id" };
            GridView1.DataSource = ds.Tables[0];
            GridView1.DataBind();

        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            GridView1.PageIndex = 0;
            BindData();
        }

        protected void Button2_Click(object sender, EventArgs e)
        {
            if (GridView1.PageIndex > 0)
            {
                GridView1.PageIndex -= 1;
            }
            BindData();
        }

        protected void Button3_Click(object sender, EventArgs e)
        {
            if (GridView1.PageIndex < GridView1.PageCount - 1)
            {
                GridView1.PageIndex += 1;
            }
            BindData();
        }

        protected void Button4_Click(object sender, EventArgs e)
        {
            GridView1.PageIndex = GridView1.PageCount - 1;
            BindData();
        }

        protected void Button6_Click(object sender, EventArgs e)
        {
            bool flag = false;
            string sid = "";
            if (GridView1.Rows.Count >= 1)
            {
                for (int i = 0; i < GridView1.Rows.Count; i++)
                {
                    CheckBox rbtn = (CheckBox)GridView1.Rows[i].FindControl("CheckBox1");
                    if (rbtn.Checked)
                    {
                        sid = GridView1.Rows[i].Cells[1].Text;
                        string strsql = "delete from sxinwen where id=" + sid;

                        mydata myda = new mydata();
                        MySqlCommand cmd = myda.getCommand(strsql);

                        int n = myda.execNonQuery(cmd);
                        if (n > 0)
                        {
                            Response.Write("<script language=javascript> alert('删除数据成功') </script>");
                        }
                        else
                        {
                            Response.Write("<script language=javascript> alert('删除数据失败') </script>");
                        }
                    }
                }
                if (flag)
                {
                    Response.Redirect("editXinWen2.aspx?id=" + sid);
                }
            }
        }

        protected void Button7_Click(object sender, EventArgs e)
        {
            Response.Redirect("browerXinWen.aspx");
        }
    }
}